package com.jingdianjichi.subject.application.handler.subject;//package com.jingdianjichi.subject.application.handler.subject;

import com.jingdianjichi.subject.domain.entity.SubjectInfoBO;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBO;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.service.SubjectBriefService;
import com.jingdianjichi.subject.infra.basic.service.SubjectInfoService;
import com.jingdianjichi.subject.infra.basic.service.SubjectLabelService;
import com.jingdianjichi.subject.infra.basic.service.SubjectMappingService;
import com.jingdinajichi.subject.common.enmus.IsDeleteCodeEnum;
import com.jingdinajichi.subject.common.enmus.SubjectInfoTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author zwy
 * @version 1.0
 * @description: BriefTypeHandler
 * @date 2025/7/13 17:48
 */
@Slf4j
@Component
public class BriefTypeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectBriefService subjectBriefService;
    @Resource
    private SubjectInfoService subjectInfoService;
    @Resource
    private SubjectMappingService subjectMappingService;
    @Resource
    private SubjectLabelService subjectLabelService;
    /**
     * 枚举题目类型的识别
     *
     * @return
     */
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    /**
     *多选题目的插入
     *
     * @param subjectInfoBO
     */
    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        if(log.isInfoEnabled()){
            log.info("BriefTypeHandler.add.subjectInfoBO:{}",subjectInfoBO);
        }
        try{
//        将subjectInfoBO转换成subjectBrief
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setSubjectAnswer(subjectInfoBO.getSubjectAnswer());
        subjectBrief.setIsDeleted(IsDeleteCodeEnum.NOT_DELETE_CODE_ENUM.getCode());
        subjectBriefService.insert(subjectBrief);
        }catch (Exception e){
            log.error("BriefTypeHandler.add.error:{}",e);}

    }

    @Override
    public SubjectInfoBO query(SubjectInfoBO subjectInfoBO) {

//        通过题目id查询单选题表
        SubjectBrief subjectBrief= subjectBriefService.queryBySubjectId(subjectInfoBO.getId());

        subjectInfoBO.setSubjectAnswer(subjectBrief.getSubjectAnswer());


        return subjectInfoBO;
    }
}
